/**
 * Copyright 2015 Qiyi Inc. All rights reserved.
 *
 * @file:   Carousel.Dao.js
 * @author: karkarrotxu@qiyi.com
 * @date:   2016-05-30
 */
qui(
    function (require, exports, module) {

        Carousel.Dao = $.extend({}, EpgWeb.Dao, {
            cache: {},
            getChannel: function () {
                return this.getDataByName(this.cfgName.getChannel).data;
            },

            liveProgramType: function () {
                return this.getDataByName(this.cfgName.liveProgramType);
            },

            getPrograms: function () {
                return this.getDataByName(this.cfgName.programList).data;
            },
            channelList: function () {
                return this.getDataByName(this.cfgName.channelList);
            },

            getPlatformType: function () {
                return this.getDataByName(this.cfgName.PlayPlatform)
            },

            getPlatformRefer: function () {
                return this.getDataByName(this.cfgName.PlatformRefer)
            },

            getPlatSettings: function () {
                return this.getDataByName(this.cfgName.platSettings)
            },

            getContentType: function () {
                return this.getDataByName(this.cfgName.ContentType);
            },
            logType: function () {
                return this.getDataByName(this.cfgName.LogType);
            },
//            adDuration:function(){
//                return this.getDataByName(this.cfgName.Ad_duration);
//            },
            getFromCache: function (dataKey) {
                return this.cache[dataKey]
            },

            putToCache: function (dataKey, data) {
                this.cache[dataKey] = data
            },

            deleteProgramData: function (data, callback) {
                var self = this;
                self.doAuthData({
                    url: '/epg/carousel_program_delete.html',
                    doError: function () {
                        EpgWeb.Plugin.showTips({content: Carousel.Config.Hint.NO_AUTH, type: "error"})
                    },
                    doSuccess: function () {
                        SystemDialog.queryConfirm(Carousel.Config.Hint.QUERY_DEL, function (flag) {
                            if (flag === true) {
                                self.sendAjax(EpgWeb.urlConfig.programDel, 'post', data, callback, '/program/delete')
                            }
                        })
                    }
                })
            },
            programBatchDel: function (data, callback) {
                var self = this;
                self.doAuthData({
                    url: '/epg/carousel_program_delete.html',
                    doError: function () {
                        EpgWeb.Plugin.showTips({content: Carousel.Config.Hint.NO_AUTH, type: "error"})
                    },
                    doSuccess: function () {
                        SystemDialog.queryConfirm(Carousel.Config.Hint.QUERY_DEL, function (flag) {
                            if (flag === true) {
                                self.sendAjax(EpgWeb.urlConfig.programBatchDelUrl, 'post', data, callback, '/program/batchDel')
                            }
                        })
                    }
                })
            },
            programMove: function (data, callback) {
                this.sendAjax(EpgWeb.urlConfig.programMoveUrl, 'post', data, callback, '/program/move')
            },
            programToggleLock: function (data, callback) {
                this.sendAjax(EpgWeb.urlConfig.programToggleLockUrl, 'post', data, callback, '/program/toggleLock')
            },
            programIndexMove: function (data, callback) {
                this.sendAjax(EpgWeb.urlConfig.programIndexMoveUrl, 'post', data, callback, '/program/indexMove')
            },
            gridSort: function (data, callback) {
                this.sendAjax(EpgWeb.urlConfig.programDaySortUrl, 'post', data, callback, '/program/daySort')
            },
            batchAdd: function (data, callback) {
                this.sendAjax(EpgWeb.urlConfig.programBatchAddUrl, 'post', data, callback, '/program/batchAdd')
            },
            getProgramList: function (data, callback) {
                this.sendAjax(EpgWeb.urlConfig.programList, 'post', data, callback, '/program/list')
            },
            episodeBatchAdd: function (data, callback) {
                this.sendAjax(EpgWeb.urlConfig.carouselEpisodeBatchAddUrl, 'post', data, callback, '/carousel/carouselEpisode/batchAdd')
            },
            episodeIndexMove:function(data, callback){
                this.sendAjax(EpgWeb.urlConfig.carouselEpisodeIndexMoveByIndexUrl, 'post', data, callback, '/carousel/carouselEpisode/indexMove/byIndex')
            },
            getCarouselEpisodeList: function (data, callback) {
                this.sendAjax(EpgWeb.urlConfig.carouselEpisodeListUrl, 'get', data, callback, '/carousel/carouselEpisode/list')
            },
            notifyRuleChangeStatus: function (data, callback) {
                this.sendAjax(EpgWeb.urlConfig.automationChangeStatusUrl, 'get', data, callback, '/carousel/automation/changeStatus')
            },
            postModifyAdvert:function(data,callback){
                this.sendAjax(EpgWeb.urlConfig.advertModifyUrl, 'post', data, callback, '/advert/modify')
            },
            episodeBatchDel: function (data, callback) {
                var self = this;
                self.doAuthData({
                    url: '/epg/carousel_program_delete.html',
                    doError: function () {
                        EpgWeb.Plugin.showTips({content: Carousel.Config.Hint.NO_AUTH, type: "error"})
                    },
                    doSuccess: function () {
                        SystemDialog.queryConfirm(Carousel.Config.Hint.QUERY_DEL, function (flag) {
                            if (flag === true) {
                                self.sendAjax(EpgWeb.urlConfig.carouselEpisodeBatchDelUrl, 'post', data, callback, '/carousel/carouselEpisode/batchDel')
                            }
                        })
                    }
                })
            },
            automationList:function(data, callback) {
                this.sendAjax(EpgWeb.urlConfig.automationListUrl, 'get', data, callback, '/carousel/automations')
            },
            delAutomationRule:function(data, callback){
                var self = this;
                self.doAuthData({
                    url: '/epg/carousel_program_delete.html',
                    doError: function () {
                        EpgWeb.Plugin.showTips({content: Carousel.Config.Hint.NO_AUTH, type: "error"})
                    },
                    doSuccess: function () {
                        SystemDialog.queryConfirm(Carousel.Config.Hint.QUERY_DEL, function (flag) {
                            if (flag === true) {
                                self.sendAjax(EpgWeb.urlConfig.automationDelUrl, 'post', data, callback, '/carousel/automation/del')
                            }
                        })
                    }
                })
            },
            changeStatusAutomationRule:function(data, callback){
                this.sendAjax(EpgWeb.urlConfig.automationChangeStatusUrl, 'get', data, callback, '/carousel/automation/changeStatus')
            }

        })
        Carousel.Dao.cfgName = $.extend({}, EpgWeb.Dao.cfgName, {
            enumName: "programTypeData",
            listName: "mockData",
            fatherId: 0,
            ContentType: "ContentType",
            getChannelList: "getChannelList",
            getProgramList: "programList",
            channelList: "channelList",
            platSettings: "platSettings",
            PlayPlatform: "PlayPlatform",
            PlatformRefer: "PlatformRefer",
            yesterdayEndTime: 0,
       //     Ad_duration:"ad_duration",
            ad_selected:0
        });
    }
);